package com.zonta.finance.admin.controller;

import com.zonta.finance.common.dto.ApiResponse;
import com.zonta.finance.common.dto.TokenResponse;
import com.zonta.finance.domain.form.*;
import com.zonta.finance.serivce.MemberLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户登录接口")
@RestController
@Slf4j
@RequestMapping("/login")
@RequiredArgsConstructor
public class LoginController {
    private final MemberLoginService memberLoginService;

    @ApiOperation("获取客户端id")
    @GetMapping("/getClientId")
    public ApiResponse<String> getClientId(){
        return ApiResponse.success(memberLoginService.getClientId());
    }

    @ApiOperation("获取图形验证码")
    @GetMapping("/getBase64Code")
    public ApiResponse<String> getBase64Code(@ModelAttribute @Validated GetBaseCodeForm baseCodeForm){

       return ApiResponse.success(memberLoginService.getBase64Code(baseCodeForm));
    }
    @ApiOperation("获取短信验证码")
    @GetMapping(value = "/sendSmsCode")
    public ApiResponse<Void> sendSmsCode(@Validated @ModelAttribute GetSmsCodeForm form){
        memberLoginService.sendSmsCode(form);
        return ApiResponse.success();
    }
    @ApiOperation("手机密码登录")
    @PostMapping("/phonePasswordLogin")
    public ApiResponse<TokenResponse> phonePasswordLogin(@Validated @RequestBody PhonePasswordLoginForm form){
        return ApiResponse.success(memberLoginService.phonePasswordLogin(form));
    }

    @ApiOperation("手机短信登录")
    @PostMapping("/phoneSmsCodeLogin")
    public ApiResponse<TokenResponse> phoneSmsCodeLogin(@Validated @RequestBody PhoneSmsCodeLoginForm form){
        return ApiResponse.success(memberLoginService.phoneSmsCodeLogin(form));
    }

    @ApiOperation("获取客户端token")
    @GetMapping(value = "/getClientToken")
    public ApiResponse<TokenResponse> getClientToken(@Validated @ModelAttribute GetClientTokenForm form) {
        TokenResponse result = memberLoginService.getClientToken(form.getClientId());
        return ApiResponse.success(result);
    }
}
